
/**********************************************************************************************************************
  COPYRIGHT
-----------------------------------------------------------------------------------------------------------------------
  \par      copyright
  \verbatim
  Copyright (c) 2015 by Vector Informatik GmbH.                                                  All rights reserved.

                This software is copyright protected and proprietary to Vector Informatik GmbH.
                Vector Informatik GmbH grants to you only those rights as set out in the license conditions.
                All other rights remain with Vector Informatik GmbH.
  \endverbatim
-----------------------------------------------------------------------------------------------------------------------
  FILE DESCRIPTION
-----------------------------------------------------------------------------------------------------------------------
  \file  File:  startup.c
      Project:  Vector Basic Runtime System for BTLD
       Module:  Startup for Platform RH850
    Generator:  -

  \brief Description:  This file consists of the Startup Code.
**********************************************************************************************************************/

/**********************************************************************************************************************
  AUTHOR IDENTITY
-----------------------------------------------------------------------------------------------------------------------
  Name                          Initials      Company
-----------------------------------------------------------------------------------------------------------------------
  Markus Feninger               visfr         Vector Informatik GmbH
-----------------------------------------------------------------------------------------------------------------------
  REVISION HISTORY
 ----------------------------------------------------------------------------------------------------------------------
  Version   Date        Author  Change Id     Description
 ----------------------------------------------------------------------------------------------------------------------
  01.00.00  2015-04-22  visfr   -             Initial version for BTLD (using OS)
**********************************************************************************************************************/

/**********************************************************************************************************************
  INCLUDES
**********************************************************************************************************************/
#include "v_cfg.h"

#pragma asm
--------------------------------------------------------------------------
--------------- Definition of external functions -------------------------
--------------------------------------------------------------------------
.globl __usr_init
.extern __start

-- macro to generate count nop instructions
.macro nops count
.rept count
nop
.endr
.endm

--------------------------------------------------------------------------
.section ".Startup",.text
--------------------------------------------------------------------------
--------------- Basic Initialisation of the controller -------------------
--------------------------------------------------------------------------
__usr_init:
  -- Initialization of the global pointer
  movhi	hi(___ghsbegin_sdabase),zero,gp
  movea	lo(___ghsbegin_sdabase),gp,gp

  -- Initialization of the text pointer
  movhi	hi(___ghsbegin_robase),zero,tp
  movea	lo(___ghsbegin_robase),tp,tp

  -- Initialization of the stack pointer
  movhi	hi(___ghsend_stack-4),zero,sp
  movea	lo(___ghsend_stack-4),sp,sp
  mov -4,r1
  and r1,sp

  -- Initialization of the interrupt base pointer
  mov 0x00002200u,r1
  ldsr r1,intbp,1

  -- Initialization of the exception handler base pointer
  mov 0x00002000u,r1
  ldsr r1,ebase,1

  -- Jump to the initialisation functions of the library
  -- and from there to main()
  jr __start


--===========================================================================--
-- Exception interrupt vector redirection table
--===========================================================================--
-- Exception interrupt vector table generated by OS
-- .align 4
-- .section ".ExceptionVectorTable",.text

--===========================================================================--
-- Interrupt vector table
--===========================================================================--  
-- Interrupt vector table generated by OS
-- .align 4
-- .section ".intvect",.text

#pragma endasm

